package project2.ui.game;

import project2.config.Config;
import project2.resources.Images;

import javax.swing.*;
import java.awt.*;

/**
 * 加载面板
 */
public class GameLoadingPanel extends JPanel {
    private static final long serialVersionUID = 1L;

    private final JLabel gameLoadingPlaneLabel;
    private final ImageIcon[] gameLoadingPlaneImgList = new ImageIcon[3];

    public GameLoadingPanel() {
        this.gameLoadingPlaneImgList[0] = new ImageIcon(Images.GAME_LOADING_IMG1);
        this.gameLoadingPlaneImgList[1] = new ImageIcon(Images.GAME_LOADING_IMG2);
        this.gameLoadingPlaneImgList[2] = new ImageIcon(Images.GAME_LOADING_IMG3);

        gameLoadingPlaneLabel = new JLabel();// 会动的飞机LOGO
        gameLoadingPlaneLabel.setOpaque(false);

        JLabel gameLoadingTextLabel = new JLabel(new ImageIcon(Images.GAME_LOADING_TEXT_IMG));// 图片标题
        gameLoadingTextLabel.setOpaque(false);

        JPanel panelUp = new JPanel();
        panelUp.setOpaque(false);
        panelUp.add(gameLoadingPlaneLabel);// 默认流式居中布局

        JPanel panelDown = new JPanel();
        panelDown.setOpaque(false);
        panelDown.add(gameLoadingTextLabel);// 默认流式居中布局

        this.setLayout(new GridLayout(2, 1));// 网格布局
        this.setOpaque(false);
        this.add(panelUp);
        this.add(panelDown);
    }

    public void loadingGame() {
        for (int i = 0; i < 3; i++) {
            this.gameLoadingPlaneLabel.setIcon(this.gameLoadingPlaneImgList[i]);
            try {
                Thread.sleep(Config.GAME_LOADING_INTERVAL);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
